//
//  XWClickableTBHeaderFooterBaseView.swift
//  XiaoweHearingAid
//
//  Created by Riven on 2023/3/16.
//

import UIKit

class XWClickableTBHeaderFooterBaseView: XWHTBHeaderFooterBaseView {

    lazy var subTitleLb = UILabel()
    
    lazy var subIconView = UIImageView()
    
    lazy var button = UIButton()
    
    var clickCallback: (() -> Void)?
    
    override func addSubViews() {
        super.addSubViews()
        contentView.addSubview(subTitleLb)
        contentView.addSubview(subIconView)
        
        contentView.addSubview(button)

        titleLb.font = AppFont.harmonyOSSans(ofSize: 20, weight: .medium)
        titleLb.textColor = majorTextColor
        titleLb.numberOfLines = 0
        titleLb.adjustsFontSizeToFitWidth = true
        
        subTitleLb.font = AppFont.harmonyOSSans(ofSize: 16, weight: .regular)
        subTitleLb.textColor = minorTextColor
        subTitleLb.numberOfLines = 0
        subTitleLb.adjustsFontSizeToFitWidth = true
        subTitleLb.textAlignment = .right
        
        button.addTarget(self, action: #selector(clickButton), for: .touchUpInside)
        
        subIconView.image = R.image.detail_icon()
    }
    
    override func relayoutSubViews() {
        titleLb.snp.makeConstraints { make in
            make.left.equalToSuperview()
            make.width.equalTo(170)
            make.height.equalTo(25)
            make.centerY.equalToSuperview()
        }
        
        subIconView.snp.makeConstraints { make in
            make.size.equalTo(22)
            make.right.equalToSuperview()
            make.centerY.equalToSuperview()
        }
        
        subTitleLb.snp.makeConstraints { make in
            make.right.equalTo(subIconView.snp.left)
            make.centerY.equalToSuperview()
            make.height.equalTo(titleLb)
            make.width.equalTo(100)
        }
        
        button.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    @objc private func clickButton() {
        clickCallback?()
    }
    
}
